home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-29  |  5.5 KB  |  234 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     draw.c
  4.  
  5.     This module draws the contents of windows.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <string.h>
  13. #include <stdio.h>
  14.  
  15. #include "glob.h"
  16. #include "draw.h"
  17. #include "header.h"
  18. #include "util.h"
  19. #include "datetime.h"
  20.  
  21.  
  22. /*    DrawSectionMessage draws the "Section x of y" message in a window. */
  23.  
  24. void DrawSectionMessage (WindowPtr wind)
  25. {
  26.     TWindow **info;
  27.     short fontNum,savedFontNum,savedFontSize;
  28.     CStr255 msg,num;
  29.     
  30.     info = (TWindow**) GetWRefCon(wind);
  31.     GetFNum("\pMonaco",&fontNum);
  32.     savedFontNum = wind->txFont;
  33.     savedFontSize = wind->txSize;
  34.     TextFont(fontNum);
  35.     TextSize(9);
  36.     strcpy(msg, "Section ");
  37.     NumToString((**info).curSection+1, (StringPtr)num);
  38.     p2cstr((StringPtr)num);
  39.     strcat(msg, num);
  40.     strcat(msg, " of ");
  41.     NumToString((**info).numSections, (StringPtr)num);
  42.     p2cstr((StringPtr)num);
  43.     strcat(msg, num);
  44.     MoveTo(kTextMargin, wind->portRect.bottom-4);
  45.     c2pstr(msg);
  46.     DrawString((StringPtr)msg);
  47.     TextFont(savedFontNum);
  48.     TextSize(savedFontSize);
  49. }
  50.  
  51.  
  52. /*    DrawArticlePanel draws the panel below the window title bar for
  53.     article windows.
  54. */
  55.  
  56. static void DrawArticlePanel (WindowPtr wind)
  57. {
  58.     WindowPtr parent;
  59.     TWindow **info, **parentInfo;
  60.     TSubject subject, **subjectArray;
  61.     Handle text;
  62.     short panelHeight,windWidth;
  63.     CStr255 author, org, date;
  64.     char msg[522];
  65.     FontInfo fontInfo;
  66.     short len, width1, width2, v;
  67.     char c;
  68.     
  69.     info = (TWindow**)GetWRefCon(wind);
  70.     panelHeight = (**info).panelHeight;
  71.     text = (**info).fullText;
  72.     GetFontInfo(&fontInfo);
  73.     
  74.     windWidth = wind->portRect.right - wind->portRect.left;
  75.     MoveTo(0,panelHeight-3);
  76.     LineTo(windWidth,panelHeight-3);
  77.     MoveTo(0,panelHeight-1);
  78.     LineTo(windWidth,panelHeight-1);
  79.     
  80.     GetAuthorFromHeader(text, author);
  81.     strcpy(msg, "Author: ");
  82.     strcat(msg, author);
  83.     v = fontInfo.ascent + 3;
  84.     MoveTo(kTextMargin, v);
  85.     len = strlen(msg);
  86.     DrawText(msg, 0, len);
  87.     
  88.     
  89.     FindHeader(text, "Organization:", org, sizeof(org));
  90.     strcpy(msg, "Organization: ");
  91.     strcat(msg, org);
  92.     v += fontInfo.ascent + fontInfo.descent + fontInfo.leading;
  93.     MoveTo(kTextMargin, v);
  94.     len = strlen(msg);
  95.     DrawText(msg, 0, len);
  96.     
  97.     FindHeader(text, "Date:", date, sizeof(date));
  98.     Cleanup822Date(date);
  99.     v += fontInfo.ascent + fontInfo.descent + fontInfo.leading;
  100.     MoveTo(kTextMargin, v);
  101.     len = strlen(date);
  102.     DrawText(date, 0, len);
  103.     width1 = TextWidth(date, 0, len);
  104.     
  105.     if ((**info).kind == kArticle) {
  106.         parent = (**info).parentWindow;
  107.         parentInfo = (TWindow**)GetWRefCon(parent);
  108.         subjectArray = (**parentInfo).subjectArray;
  109.         subject = (*subjectArray)[(**info).parentSubject];
  110.         if (subject.threadLength > 1) {
  111.             c = subject.threadOrdinal == subject.threadLength ? '•' : '…';
  112.             sprintf(msg, "Article %d of %d in thread %c", 
  113.                 subject.threadOrdinal, subject.threadLength, c);
  114.             len = strlen(msg);
  115.             width2 = TextWidth(msg, 0, len);
  116.             if (width1 + width2 + 2*kTextMargin + 10 < windWidth) {
  117.                 MoveTo(windWidth - kTextMargin - width2, v);
  118.                 DrawText(msg, 0, len);
  119.             }
  120.         }
  121.     }
  122. }
  123.  
  124.  
  125. /*    DrawMessagePanel draws the panel below the window title bar for
  126.     message windows.
  127. */
  128.  
  129. static void DrawMessagePanel (WindowPtr wind)
  130. {
  131.     TWindow **info;
  132.     short panelHeight, windWidth;
  133.     Handle text;
  134.     CStr255 line, temp;
  135.     CStr255 msg;
  136.     FontInfo fontInfo;
  137.     short len;
  138.     EWindowKind kind;
  139.     short maxWidth;
  140.     
  141.     info = (TWindow**)GetWRefCon(wind);
  142.     kind = (**info).kind;
  143.     panelHeight = (**info).panelHeight;
  144.     windWidth = wind->portRect.right - wind->portRect.left;
  145.     MoveTo(0,panelHeight-3);
  146.     LineTo(windWidth,panelHeight-3);
  147.     MoveTo(0,panelHeight-1);
  148.     LineTo(windWidth,panelHeight-1);
  149.     
  150.     text = (**info).headerShown ? (Handle)TEGetText((**info).theTE) : 
  151.         (**info).headerText;
  152.     if (kind == kPostMessage) {
  153.         FindHeader(text, "Newsgroups:", line, 200);
  154.     } else {
  155.         FindHeader(text, "To:", line, 200);
  156.         PrettifyName(line);
  157.     }
  158.     strcpy(msg, kind == kPostMessage ? "Posting to: " : "Mail message to: ");
  159.     strcat(msg, line);
  160.     
  161.     GetFontInfo(&fontInfo);
  162.     MoveTo(kTextMargin, 
  163.         ((panelHeight - 4 - fontInfo.ascent - fontInfo.descent) >> 1) +
  164.             fontInfo.ascent);
  165.     len = strlen(msg);
  166.     maxWidth = wind->portRect.right - 70;
  167.     while (TextWidth(msg, 0, len) > maxWidth) len--;
  168.     DrawText(msg, 0, len);
  169. }
  170.  
  171.  
  172. /*    DrawWindow is called to re-draw window contents in response
  173.     to update events.
  174. */
  175.  
  176. static void DrawWindow (WindowPtr wind)
  177. {
  178.     TWindow **info;
  179.     EWindowKind kind;
  180.     Rect clipRect;
  181.  
  182.     info = (TWindow**) GetWRefCon(wind);
  183.     kind = (**info).kind;    
  184.     
  185.     clipRect = wind->portRect;
  186.     clipRect.top += (**info).panelHeight;
  187.     ClipRect(&clipRect);
  188.     DrawGrowIcon(wind);
  189.     ClipRect(&wind->portRect);
  190.     switch (kind) {
  191.         case kFullGroup:
  192.         case kNewGroup:
  193.         case kUserGroup:
  194.         case kSubject:
  195.             LUpdate(wind->visRgn,(**info).theList);
  196.             break;
  197.         case kArticle:
  198.         case kMiscArticle:
  199.         case kPostMessage:
  200.         case kMailMessage:
  201.             UpdtControl(wind,wind->visRgn);
  202.             TEUpdate(&wind->portRect,(**info).theTE);
  203.             if ((**info).numSections > 1) DrawSectionMessage(wind);
  204.             if (kind == kArticle || kind == kMiscArticle) {
  205.                 DrawArticlePanel(wind);
  206.             } else {
  207.                 DrawMessagePanel(wind);
  208.             }
  209.             break;
  210.     }
  211. }
  212.  
  213.  
  214. /* HandleUpdate: Handles update events */
  215.  
  216. void HandleUpdate (WindowPtr wind)
  217. {
  218.     GrafPtr savePort;
  219.     
  220.     if (((WindowPeek)wind)->windowKind < 0 || 
  221.         ((WindowPeek)wind)->windowKind == dialogKind) return;
  222.     GetPort(&savePort);
  223.     SetPort(wind);
  224.     BeginUpdate(wind);
  225.     if (!IsStatusWindow(wind)) {
  226.         EraseRect(&wind->portRect);
  227.         DrawWindow(wind);
  228.     } else {
  229.         UpdateStatus();
  230.     }
  231.     EndUpdate(wind);
  232.     SetPort(savePort);
  233. }
  234.